package com.pai4j.client.service;

import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.common.exception.BusinessException;
import com.pai4j.domain.vo.request.request.CommentSaveVO;
import com.pai4j.domain.vo.response.CommentResponseVO;
import com.pai4j.remote.act.ICommentClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 */
@Service
public class CommentService {

    @Autowired
    private ICommentClient commentClient;

    /**
     * 发布评论
     * @param
     * @return
     */
    public Long saveComment(CommentSaveVO vo) {

        // RPC 请求ACT微服务实现π圈动态评论发布核心流程
        PAIResponseBean<Long> responseBean = commentClient.saveComment(vo);
        if (PAIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new BusinessException(responseBean.getMessage());
    }

    /**
     * 删除评论
     * RPC 请求ACT微服务实现评论删除核心流程
     * @param
     * @return
     */
    public void deleteComment(Long id, String currentUserId) {

        commentClient.deleteComment(id, currentUserId);
    }

    /**
     * 批量获取评论
     * RPC 请求ACT微服务实现评论查询核心流程
     * @param
     * @return
     */
    public PAIPageResponseBeanUtil<List<CommentResponseVO>> queryCommentByCondition(String content,
                                                                                    Long resourceId, String resourceType,
                                                                                    Integer pageNo, Integer pageSize,
                                                                                    Boolean isHot, Boolean isNew) {
       return commentClient.queryComments(resourceId, resourceType, content, isHot, isNew, pageNo, pageSize);
    }
}
